package com.blog.module.photos.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.commons.CommonsMultipartFile;




import com.blog.common.config.FileConfig;
import com.blog.common.controller.BaseAdminController;
import com.blog.common.mybatis.Page;
import com.blog.common.utils.FileUtil;
import com.blog.module.photos.pojo.Photos;
import com.blog.module.photos.service.PhotosService;

@Controller
@RequestMapping("admin/photos/**")
public class PhotosAdminController extends BaseAdminController {

	@Autowired
	private PhotosService photosService;

	@RequestMapping("list")
	public String page(Model model, Photos photos) {

		Page page = photosService.pagePhotos(photos);
		model.addAttribute("page", page);

		return "admin/photos/list";
	}

	@RequestMapping(value = "/{id}/edit", method = RequestMethod.GET)
	public String edit(Model model, @PathVariable Integer id) {

		Photos photos = photosService.selectById(id);
		model.addAttribute("photos", photos);
		return "admin/photos/edit";
	}

	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	public String edit(Photos photos) {
		
		photosService.update(photos);
		return redirect("/admin/photos/list");
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add() {

		return "admin/photos/add";
	}

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public String add(Photos photos) {
		
		photosService.insert(photos);
		
		return redirect("/admin/photos/list");
	}
}
